package com.easyadmin.modules.stock.controller;

import java.util.Arrays;
import java.util.Map;

import com.easyadmin.common.web.base.BaseController;
import com.easyadmin.common.web.domain.request.PageDomain;
import com.easyadmin.common.web.domain.response.Result;
import com.easyadmin.common.web.domain.response.module.ResultTable;
import com.easyadmin.modules.stock.domain.SysFuturesEntity;
import com.easyadmin.modules.stock.domain.SysStockPriceWarnEntity;
import com.easyadmin.modules.stock.service.SysStockPriceWarnService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.bind.annotation.*;

/**
 * 股票价格预警表
 *
 * @author wanzenghui
 * @email lemon_wan@aliyun.com
 * @date 2025-04-03 20:54:57
 */
@RestController
@RequestMapping("/stock/warn")
public class SysStockPriceWarnController extends BaseController {
    @Autowired
    private SysStockPriceWarnService sysStockPriceWarnService;



    /**
     * Describe: 基础路径
     */
    private static String MODULE_PATH = "stock/warn/";



    /**
     * Describe: 获取列表视图
     * Param ModelAndView
     * Return 列表视图
     */
    @GetMapping("main")
    @ApiOperation(value = "获取列表视图")
    @PreAuthorize("hasPermission('/stock/warn/main','stock:warn:main')")
    public ModelAndView main() {
        return jumpPage(MODULE_PATH + "main");
    }


    /**
     * Describe: 获取新增视图
     * Param ModelAndView
     * Return 角色新增视图
     */
    @GetMapping("add")
    @ApiOperation(value = "新增视图")
    @PreAuthorize("hasPermission('/stock/warn/add','stock:warn:add')")
    public ModelAndView add() {
        return jumpPage(MODULE_PATH + "add");
    }


    /**
     * Describe: 获取列表视图
     * Param ModelAndView
     * Return 列表视图
     */
    @GetMapping("amain")
    @ApiOperation(value = "获取列表视图")
    @PreAuthorize("hasPermission('/stock/warn/amain','stock:warn:amain')")
    public ModelAndView amain() {
        return jumpPage(MODULE_PATH + "amain");
    }


    /**
     * 分页查询    审核通过的
     */
    @ResponseBody
    @GetMapping("/alist")
    @PreAuthorize("hasPermission('/stock/warn/alist','stock:warn:alist')")
    public ResultTable alist(@ModelAttribute SysStockPriceWarnEntity sysStockPriceWarnEntity, PageDomain pageDomain) {
        sysStockPriceWarnEntity.setAuditStatus("1");
        PageInfo<SysStockPriceWarnEntity> pageInfo = sysStockPriceWarnService.aqueryPage(sysStockPriceWarnEntity, pageDomain);
        return pageTable(pageInfo.getList(), pageInfo.getTotal());
    }



    /**
     * 分页查询
     */
    @ResponseBody
    @GetMapping("/list")
    @PreAuthorize("hasPermission('/stock/warn/list','stock:warn:list')")
    public ResultTable list(@ModelAttribute SysStockPriceWarnEntity sysStockPriceWarnEntity, PageDomain pageDomain) {
        PageInfo<SysStockPriceWarnEntity> pageInfo = sysStockPriceWarnService.
                queryPage(sysStockPriceWarnEntity, pageDomain);
        return pageTable(pageInfo.getList(), pageInfo.getTotal());
    }


    /**
     * Describe: 删除某条数据
     * Param: id
     * Return: Result
     */
    @DeleteMapping("/remove/{id}")
    @ApiOperation(value = "删除某条数据")
    @PreAuthorize("hasPermission('/stock/warn/remove','stock:warn:remove')")
    public Result remove(@PathVariable String id) {
        return decide(sysStockPriceWarnService.remove(id));
    }



    /**
     * Describe: 用户批量删除接口
     * Param: ids
     * Return: Result
     */
    @DeleteMapping("batchRemove/{ids}")
    @ApiOperation(value = "批量删除数据")
    @PreAuthorize("hasPermission('/stock/warn/remove','stock:warn:remove')")
    public Result batchRemove(@PathVariable String ids) {
        return decide(sysStockPriceWarnService.batchRemove(ids.split(",")));
    }



    /**
     * Describe: 获取修改视图
     * Param ModelAndView
     * Return 修改视图
     */
    @GetMapping("edit")
    @ApiOperation(value = "获取修改视图")
    @PreAuthorize("hasPermission('/stock/warn/edit','stock:warn:edit')")
    public ModelAndView edit(ModelAndView modelAndView, String id) {
        modelAndView.addObject("stockWarn", sysStockPriceWarnService.getById(id));
        modelAndView.setViewName(MODULE_PATH + "edit");
        return modelAndView;
    }



    /**
     * Describe: 修改角色信息
     * Param SysRole
     * Return 执行结果
     */
    @PutMapping("update")
    @ApiOperation(value = "修改数据")
    @PreAuthorize("hasPermission('/stock/warn/edit','stock:warn:edit')")
    public Result update(@RequestBody SysStockPriceWarnEntity sysStockPriceWarnEntity) {
        return decide(sysStockPriceWarnService.update(sysStockPriceWarnEntity));
    }


    /**
     * Describe: 同步产品年纪
     * Param SysRole
     * Return 执行结果
     */
    @DeleteMapping("synch/{ids}")
    @ApiOperation(value = "修改数据")
    @PreAuthorize("hasPermission('/stock/warn/synch','stock:warn:synch')")
    public Result synch(@PathVariable String ids) {
        return decide(sysStockPriceWarnService.synch(ids));
    }


}
